<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Team extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id',
        'name',
        'tax_id',
        'address',
        'mobile',
        'bank',
        'bank_number',
        'bank_account',
        'email',
        'postal_code',
        'entrusted_agent',
        'agent',
        'remarks',
    ];

    const POSTONLY = [
        'user_id',
        'name',
        'tax_id',
        'address',
        'mobile',
        'bank',
        'bank_number',
        'bank_account',
        'email',
        'postal_code',
        'entrusted_agent',
        'agent',
        'remarks',
    ];


    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','name');
    }


    public function application()
    {
        return $this->hasOne(Application::class,'source_id','id')->where('model','Team')->orderBy('id','desc');
    }
}
